package com.summer.shopping.chat.handler;

import com.summer.shopping.chat.WSInfo;
import com.summer.shopping.domain.table.Chat;
import com.summer.shopping.enums.chat.ChatInfoTypeConstant;
import com.summer.shopping.service.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;
import java.time.LocalDateTime;
@Component
public class SaveInfoToDBHandler implements WSInfoTypeHandler{

    @Autowired
    ChatService chatService;
    @Override
    public Object handleInfo(WSInfo.Standard info) {
        //存入数据库
        Chat chat = Chat.builder()
                .senderId(info.getFrom())
                .receiverId(info.getTo())
                .content(info.getContent())
                .createTime(LocalDateTime.now()).build();
        chatService.save(chat);
        return null;
    }

    @Override
    public boolean isSupport(String type) {
        for (String s : ChatInfoTypeConstant.supportSaveDBTypes()) {
            if (s.equals(type)){
                return true;
            }
        }
        return false;
    }
}
